package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class LoginDemo
{
    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        System.out.println("name = ");
        String name = scanner.nextLine();
        System.out.println("password =" );
        String passWord = scanner.nextLine();
        String sql = "select username,password,nickname\n" +
                "from userinfo1 where username = '" +name+ "' and password = '"+passWord+"';";
        try(Connection connection = DBUtil.getConnection())
        {
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(sql);
            if (resultSet.next())
            {
                System.out.println("***** user information *****");
                String  searchName = resultSet.getString("username");
                String searchPassword = resultSet.getString("password");
                String searchNickName = resultSet.getString("nickname");
                System.out.println("name = " + searchName + "  password = " + searchNickName + "  nickname = " + searchNickName);
            }else
            {
                System.out.println("账号或密码有误");
            }


        }catch (SQLException e)
        {
            e.printStackTrace();
        }
    }
}
